﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

using TapMe.Model;

using GalaSoft.MvvmLight.Messaging;

namespace PhoneApp1.View
{
    public partial class TaskSelectPage : PhoneApplicationPage
    {

        private const string GAME_PLAY_PAGE = "/View/GamePlayPage.xaml";

        public TaskSelectPage()
        {
            InitializeComponent();
            Messenger.Default.Register<GoToPageMessage>(
                this, (action) => ReceiveMessage( action )
            );
        }

        public void HandleLevelSelection(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri(GAME_PLAY_PAGE, UriKind.Relative));
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);
            if (NavigationService.CanGoBack)
            {
                NavigationService.RemoveBackEntry();
            }
        }

        private void ReceiveMessage(GoToPageMessage msg)
        {
            NavigationService.Navigate(new Uri(msg.PageName, UriKind.Relative));
        }
    }
}